package com.jiguangssp.addemo.act;

import androidx.constraintlayout.widget.ConstraintLayout;

import android.os.Bundle;

import com.jiguangssp.addemo.R;
import com.jiguangssp.addemo.util.Constants;

import xyz.adscope.amps.ad.banner.AMPSBannerAd;
import xyz.adscope.amps.ad.banner.AMPSBannerLoadEventListener;
import xyz.adscope.amps.common.AMPSError;
import xyz.adscope.amps.config.AMPSRequestParameters;
import xyz.adscope.amps.tool.util.AMPSScreenUtil;

public class BannerActivity extends BaseAdActivity {

    private AMPSBannerAd ampsBannerAd;
    private ConstraintLayout constraintLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_banner);

        constraintLayout = findViewById(R.id.constraint_act_banner);
        loadAd();
    }

    @Override
    public void loadAd() {
        reqBannerAd();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (ampsBannerAd != null) {
            ampsBannerAd.destroy();
        }
        ampsBannerAd = null;
    }

    private void reqBannerAd() {
        AMPSRequestParameters parameter = new AMPSRequestParameters.Builder()
                .setSpaceId(Constants.JG_PUB_SPACE_ID_BANNER)//Banner广告位id
                .setTimeOut(8000)//超时时间
                .setWidth(AMPSScreenUtil.getScreenWidth(this))//banner宽，单位px
                .setHeight((int) (AMPSScreenUtil.getScreenWidth(this) / 6.4))//banner高，单位px
                .build();
        ampsBannerAd = new AMPSBannerAd(BannerActivity.this, parameter, new AMPSBannerLoadEventListener() {
            @Override
            public void onAmpsAdLoaded() {

                ampsBannerAd.show(constraintLayout);
            }

            @Override
            public void onAmpsAdFailed(AMPSError ampsError) {

            }

            @Override
            public void onAmpsAdShow() {

            }

            @Override
            public void onAmpsAdClicked() {

            }

            @Override
            public void onAmpsAdDismiss() {

            }
        });
        ampsBannerAd.loadAd();
    }
}